class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        int len=nums.size();
        int l=0;
        int r=len-1;
        int total;
        vector<int> temp;
        temp=nums;
        sort(temp.begin(),temp.end());
        while(l<r){
            total=temp[l]+temp[r];
            if(total<target)l++;
            else if(total>target)r--;
            else break;
        }
        l=find(nums.begin(),nums.end(),temp[l])-nums.begin();
        nums[l]=-100000;
        r=find(nums.begin(),nums.end(),temp[r])-nums.begin();
        return {l,r};
    }
};